<template>
	<view>
		<u-tabbar :value="current?current:0" :fixed="true" :placeholder="true" :safeAreaInsetBottom="true"
			@change="tabbarChange">
			<u-tabbar-item text="首页" icon="home"></u-tabbar-item>
			<u-tabbar-item text="维保" icon="order"></u-tabbar-item>
			<u-tabbar-item icon="scan"></u-tabbar-item>
			<u-tabbar-item text="集控设置" icon="coupon"></u-tabbar-item>
			<u-tabbar-item text="我的" icon="account"></u-tabbar-item>
		</u-tabbar>
	</view>
</template>

<script>
	import {
		getSiteInfoID
	} from '@/api/common.js';
	export default {
		props: {
			current: Number
		},
		data() {
			return {
				id: '',
				list: [{
						"pagePath": "pages/index/index"
					},
					{
						"pagePath": "pages/maintenance_service/maintenance_index"
					},
					{
						"pagePath": "pages/scan/scan"
					},
					{
						"pagePath": "pages/control_setting/control_index"
					},
					{
						"pagePath": "pages/mine/mine"
					}
				]
			}
		},
		methods: {
			tabbarChange(e) {
				console.log("1111:" + e + this.list[e].pagePath)
				var that = this
				if (e == 2) {
					// 允许从相机和相册扫码
					uni.scanCode({
						success: function(res) {
							console.log('条码类型：' + res.scanType);
							console.log('条码内容：' + res.result);
							//站点信息获取
							getSiteInfoID({
								syscode: res.result
							}).then(res1 => {
								console.log('站点信息' + JSON.stringify(res1));
								that.id = res1;

								uni.navigateTo({
									url: '/pages/device/device?id=' + that.id
								})

							}).catch(err => {
								console.log(err);
								uni.showToast({
									title: err,
									icon: 'none'
								});
							})
							// uni.navigateTo({
							// 	url: '/pages/device/device?id=' + res.result
							// })
						},
						fail() {
							uni.showToast({
								icon: 'none',
								title: '此设备暂不支持扫码功能',
							})
						}
					});
				} else {
					uni.switchTab({
						url: '/' + this.list[e].pagePath
					})
				}
			}
		}
	}
</script>

<style>

</style>